#include "algorithmsitem.h"
#include "ui_algorithmsitem.h"

#include <QRegularExpression>

extern QVector<QString> algorithms;
algorithmsItem::algorithmsItem(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::algorithmsItem)
{
    ui->setupUi(this);
    QList<QCheckBox*> checkBoxs =this->findChildren<QCheckBox*>();
    foreach(QString alg,algorithms){
        foreach(QCheckBox* box,checkBoxs){
            if(alg==box->text().replace("-","_")){
                box->setChecked(true);
            }
        }
    }

}

algorithmsItem::~algorithmsItem()
{
    delete ui;
}

void algorithmsItem::on_pushButton_clicked()
{
    QList<QCheckBox*> checkBoxs =this->findChildren<QCheckBox*>();
    algorithms.clear();
    foreach(QCheckBox* box,checkBoxs){
        if(box->isChecked()){
            algorithms.push_back(box->text().replace("_","-"));
        }
    }
    this->close();
}






void algorithmsItem::on_searchText_textChanged(const QString &text)
{
    QList<QCheckBox*> checkBoxes =this->findChildren<QCheckBox*>();
    for (QCheckBox *checkBox : checkBoxes)
    {
        QString checkBoxText = checkBox->text();

        // 使用正则表达式进行模糊匹配
        QRegularExpression regex(text, QRegularExpression::CaseInsensitiveOption);
        bool match = regex.match(checkBoxText).hasMatch();

        // 根据匹配结果隐藏或显示复选框
        checkBox->setVisible(match);
    }
}
